set(TOOLCHAIN_ROOT "/usr")
if(DEFINED ENV{TOOLCHAIN_ROOT})
    set(TOOLCHAIN_ROOT $ENV{TOOLCHAIN_ROOT})
endif()

set(CMAKE_C_COMPILER "${TOOLCHAIN_ROOT}/bin/clang")
set(CMAKE_CXX_COMPILER "${TOOLCHAIN_ROOT}/bin/clang++")

if(DEFINED ENV{CC})
    set(CMAKE_C_COMPILER $ENV{CC})
endif()
if(DEFINED ENV{CXX})
    set(CMAKE_CXX_COMPILER $ENV{CXX})
endif()

if(DEFINED ENV{GCC_TOOLCHAIN_ROOT})
    set(GCC_COMPILE_FLAGS "--gcc-toolchain=$ENV{GCC_TOOLCHAIN_ROOT}")
    set(GCC_LINK_FLAGS "-Wl,-rpath -Wl,$ENV{GCC_TOOLCHAIN_ROOT}/lib64")
endif()

set(LIB_FLAGS "")
if(DEFINED ENV{CXX_STDLIB})
    set(LIB_FLAGS " -stdlib=$ENV{CXX_STDLIB}")
endif()

set(CMAKE_C_FLAGS_INIT ${GCC_COMPILE_FLAGS})
set(CMAKE_CXX_FLAGS_INIT "${GCC_COMPILE_FLAGS}${LIB_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS_INIT ${GCC_LINK_FLAGS})

set(CMAKE_CXX_FLAGS_DEBUG_INIT "-O0")
set(CMAKE_CXX_FLAGS_RELEASE_INIT "-O3")
